package com.qf.action;

import java.io.IOException;
import java.sql.SQLException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.qf.model.Contact;
import com.qf.model.User;
import com.qf.service.impl.UserServiceImpl;


public class Add extends HttpServlet {
	private static final long serialVersionUID = 1L;
	private UserServiceImpl userServiceImpl=new UserServiceImpl(); 
   
    public Add() {
        super();
        // TODO Auto-generated constructor stub
    }

	
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
	
		response.setContentType("text/html;charset=utf-8");
		request.setCharacterEncoding("utf-8");
		
		
		String cname = request.getParameter("cname");
		String ctel=request.getParameter("ctel");
		String caddress = request.getParameter("caddress");
		String cremark=request.getParameter("cremark");
		int uid= Integer.parseInt(request.getParameter("uid"));
		int tid= Integer.parseInt(request.getParameter("tid"));

		
		boolean flag=false;
		try {
			flag = userServiceImpl.addContact(cname,ctel,caddress,cremark,uid,tid);
		
		
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		if(flag){
			response.getWriter().write("添加成功！");
			//response.setHeader("refresh", "2,jsp/index.jsp");
		}else{
			response.getWriter().write("添加失败！请重新添加！");
			//response.setHeader("refresh", "1,jsp/add.jsp");
		}
		
		
	
	}


	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		doGet(request, response);
	}

}
